package com.bg.rpc.utils;

import java.text.SimpleDateFormat;

/**
 * @Auther: zhengshunzhi
 * @Date: 2018/8/29 17:14
 * @Description:
 */
public class GuidCreate {
    public static void main(String[] args) {
        //调用生成id方法
        System.out.println(getGuid());
    }

    /**
     * 20位末尾的数字id
     */
    private static int Guid = 100;

    public static String getGuid() {
        GuidCreate.Guid += 1;

        long now = System.currentTimeMillis();
        //获取4位年份数字
        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMMddSS");
        //获取时间戳
        String time = dateFormat.format(now);
        String info = now + "";
        //获取三位随机数
        //int ran=(int) ((Math.random()*9+1)*100);
        //要是一段时间内的数据连过大会有重复的情况，所以做以下修改
        int ran = 0;
        if (GuidCreate.Guid > 999) {
            GuidCreate.Guid = 100;
        }
        ran = GuidCreate.Guid;

        return time + info.substring(2, info.length()) + ran;
    }
}
